<template>
	<view class="body">
		<view class="head">
			<view class="head_left" @click="back"><image src="/static/img/fanhui.png"></image></view>
			<view class="head_center hei_38_bold">网站公告</view>
			<view class="head_right hei_30_bold"></view>
		</view>
		<view class="content">
			<view class="app_content hui_24">
				 <view class="gonggao_list" v-for="(item,index) in list">
				    <view class="time qian_22">
					 {{item.created_at}}
				    </view>
					<view class="gonggao_item">
						<view class="gonggao_item_title hei_28_bold">
							{{item.title}}
						</view>
						<view class="gonggao_item_content">
							<u-parse :content="replace_em(item.content)"></u-parse>
						</view>
					</view>
					
				</view>
				<view class="zanwu" v-if="list.length==0">
					暂无数据
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import uParse from '@/components/feng-parse/parse.vue';
export default {
	data() {
		return {
			img_url: uni.getStorageSync('img_url'),
			page: 1,
			list:[],
			is_all: false,
			noticeid:'',
			type:1,
			limit:10
		};
	},
	components: {
		uParse
	},
	onShow() {},
	onReady() {},
	onLoad(option) {
		this.get_list();
	},
	//下拉刷新
	onPullDownRefresh: function() {
		this.list = [];
		this.page =1;
		this.get_list();
	},
	methods: {
		//上拉加载
		onReachBottom() {
			console.log('上拉加载');
			if (this.is_all) {
				uni.showToast({
					title: '没有更多内容了',
					duration: 2000,
					icon: 'none'
				});
				uni.stopPullDownRefresh();
			} else {
				this.page++;
				this.get_list();
			}
		},
		replace_em(str) {
			str = str.replace(/&amp;/g, "");
			str = str.replace(/&nbsp;/g, "");
			str = str.replace(/nbsp;/g, "");
			str = str.replace(/\</g, '&lt;');
			// str = str.replace(/\>/g, '&gt;');
			str = str.replace(/&gt;/g, ">");
			str = str.replace(/gt;/g, ">");
			str = str.replace(/\n/g, '<br/>');
			str = str.replace(/\[em_([0-9]*)\]/g, '<img src="https://imgxh.hongvv.com/zu/static/bkhumor-emoji/$1.gif" border="0" style="width:40rpx"/></img>');
			return str;
		},
		back() {
			uni.navigateBack();
		},
		get_list() {
			this.$http
				.get({
					url: '/api/getAnnouncements',
					data: {
						page: this.page,
						limit:this.limit
						
					}
				})
				.then(res => {
					if (res.code == 200) {
						
						this.list=this.list.concat(res.rows)
						if(res.rows.length < res.totalCount){
						    this.is_all=true
						}else{
							this.is_all=false
						}
					}
				});
		}
	},
	filters: {
		timeStamp: function(value) {
			if (value == null) {
				return 'null';
			}
			var i = (value + '').length;
			while (i++ < 13) value = value + '0';
			value = Number(value);
			var date = new Date(value);
			//date.setTime(value);
			var month = date.getMonth() + 1;
			var hours = date.getHours();
			if (hours < 10) hours = '0' + hours;
			var minutes = date.getMinutes();
			if (minutes < 10) minutes = '0' + minutes;
			var time = date.getFullYear() + '-' + month + '-' + date.getDate() + ' ' + hours + ':' + minutes;
			return time;
		}
	}
};
</script>

<style>
page{
	background-color: #f0f2f5;
}
.head {
	border-bottom: 1px solid #eeeeee;
}
.content {
}
.time{
	line-height: 58rpx;
	text-align: center;
}
.gonggao_list{
	padding: 0 10rpx;
}
.gonggao_item{
	background-color: #ffffff;
	border-radius: 10px;
	padding: 24rpx 26rpx 20rpx;
}
.gonggao_item_content{
	margin-top: 16rpx;
	line-height: 40rpx;
}
.zanwu{
	text-align: center;
	line-height: 80rpx;
}
</style>
